package com.pureut.production.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.production.domain.dto.DegreasDocumentDto;
import com.pureut.production.domain.dto.DegreasOutputDto;
import com.pureut.production.domain.dto.OutputStatisticsDto;
import com.pureut.production.domain.dto.WeighingFinishedMaterialProductDto;
import com.pureut.production.domain.vo.*;
import com.pureut.production.service.DegreasOutputService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 脱脂产出控制层
 */
@RestController
@RequestMapping("/degreas_output")
public class DegreasOutputController extends BaseController {

    /**
     * 脱脂产出service
     */
    @Resource
    DegreasOutputService degreasOutputService;

    /**
     * 脱脂产出列表
     *
     * @param degreasOutputVo
     * @return
     */
    @RequiresPermissions("productionTube:produAdm:degrproduc:degparaorder:list")
    @GetMapping("/list")
    public TableDataInfo degreasOutputList(DegreasOutputVo degreasOutputVo) {
        startPage();
        // 脱脂制令单列表
        List<DegreasOutputDto> list = degreasOutputService.getList(degreasOutputVo);
        return getDataTable(list);
    }

    /**
     * 脱脂产出新增
     */
    @Log(title = "脱脂制令单新增", businessType = BusinessType.INSERT)
    @GetMapping("/add")
    public AjaxResult addDegreasOutput(@RequestBody DegreasOutputVo degreasOutputVo) {
        return toAjax(degreasOutputService.addDegreasOutput(degreasOutputVo));
    }

    /**
     * 产出
     */
    @Log(title = "脱脂制令单产出", businessType = BusinessType.UPDATE)
    @RequiresPermissions("productionTube:produAdm:degrproduc:degparaorder:printOut")
    @PostMapping("/outPut")
    public AjaxResult outPut(@RequestBody DegreasOutputDetailVo degreasOutputDetailVo) throws Exception {
        return toAjax(degreasOutputService.outPut(degreasOutputDetailVo));
    }

    /**
     * 扫描入库
     */
    @Log(title = "脱脂制令单扫描入库", businessType = BusinessType.UPDATE)
    @RequiresPermissions("productionTube:produAdm:degrproduc:degparaorder:scan")
    @PostMapping("/scanIn")
    public AjaxResult scanIn(@RequestBody ScanInVo scanInVo) throws Exception {
        return AjaxResult.success(degreasOutputService.scanIn(scanInVo));
    }

    /**
     * 废料打印
     */
    @Log(title = "脱脂制令单废料打印", businessType = BusinessType.UPDATE)
    @RequiresPermissions("productionTube:produAdm:degrproduc:degparaorder:wastePrint")
    @PostMapping("/wastePrint")
    public AjaxResult wastePrint(@RequestBody WasteTubeVo wasteTubeVo) throws Exception {
        return AjaxResult.success(degreasOutputService.wastePrint(wasteTubeVo));
    }

    /**
     * 单据完成
     */
    @Log(title = "脱脂制令单单据完成", businessType = BusinessType.UPDATE)
    @RequiresPermissions("productionTube:produAdm:degrproduc:degparaorder:billOk")
    @GetMapping("/documentsFinish/{id}")
    public AjaxResult documentsFinish(@PathVariable("id") Long id) throws Exception {
        return AjaxResult.success(degreasOutputService.documentsFinish(id));
    }

    /**
     * 查看
     */
    @RequiresPermissions("productionTube:produAdm:degrproduc:degparaorder:query")
    @GetMapping("/getView/{id}")
    public AjaxResult getView(@PathVariable("id") Long id) throws Exception {
        return AjaxResult.success(degreasOutputService.getView(id));
    }

    /**
     * 产出统计
     */
    @RequiresPermissions("productionTube:produAdm:degrproduc:degparaorder:outStatistics")
    @GetMapping("/outputStatistics/{id}")
    public TableDataInfo outputStatistics(@PathVariable("id") long id) {
        startPage();
        //查询产出统计列表
        List<OutputStatisticsDto> list = degreasOutputService.outputStatistics(id);
        return getDataTable(list);
    }

}
